package LUNCH;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

public class CustTableModel extends AbstractTableModel {
	private Vector tableConVector;
	private Vector colNameVector;

	public CustTableModel(Vector tableConVector, Vector colNameVector) {
		this.tableConVector = tableConVector;
		this.colNameVector = colNameVector;
	}

	public Vector getTableConVector() {
		return tableConVector;
	}

	public int getColumnCount() {
		return this.colNameVector.size();
	}

	public int getRowCount() {
		return this.tableConVector.size();
	}

	public Object getValueAt(int x, int y) {
		Object[] o = (Object[]) this.tableConVector.elementAt(x);
		return o[y];
	}

	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	public boolean isCellEditable(int x, int y) {
		return true;
	}

	public String getColumnName(int col) {
		return this.colNameVector.elementAt(col).toString();
	}

	public void setValueAt(Object o, int x, int y) {
		Object[] o1 = (Object[]) this.tableConVector.elementAt(x);
		o1[y] = o;
		this.tableConVector.set(x, o1);
		fireTableCellUpdated(x, y);
	}

	public void addRows(Vector vec) {
		for (int i = 0; i < vec.size(); i++)
			tableConVector.add(vec.get(i));
		fireTableDataChanged();
	}

	public void removeRows(int[] rows) {
		for (int i = rows.length - 1; i >= 0; i--) {
			tableConVector.remove(rows[i]);
		}
		fireTableDataChanged();
	}

	public void removeAllRows() {
		tableConVector.removeAllElements();
		fireTableDataChanged();
	}
	public boolean isExist(Object obj,int indexCol){
		for (int i = 0; i < tableConVector.size(); i++)
		{
			Object[] objs=(Object[])tableConVector.get(i);
			if(objs[indexCol].equals(obj))
				return true;
		}
		return false;
	}
}